/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2023-05-04
 * Time:16:25
 */

/**
 * BM28 二叉树的最大深度
 */

public class maxDepth {
    private static int maxDep = 0;
    public static int maxDepth (TreeNode root) {
        // write code here
        dfs(root, 0);
        return maxDep;
    }
    public static void dfs(TreeNode node, int depth) {
        if (node == null) {
            return;
        }
        depth++;
        if (node.left == null && node.right == null) {
            maxDep = Math.max(depth, maxDep);
        }
        dfs(node.left, depth);
        dfs(node.right, depth);
    }
}
